package com.ysqcould.web.controller.curriculum;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ysqcould.curriculum.domain.CourseTag;
import com.ysqcould.curriculum.service.ICourseTagService;

/**
 * 课程标签Controller
 * 
 * @author ruoyi
 * @date 2022-09-27
 */
@RestController
@RequestMapping("/curriculum/tag")
public class CourseTagController extends BaseController
{
    @Autowired
    private ICourseTagService courseTagService;

    /**
     * 查询课程标签列表
     */
    @PreAuthorize("@ss.hasPermi('curriculum:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseTag courseTag)
    {
        startPage();
        List<CourseTag> list = courseTagService.selectCourseTagList(courseTag);
        return getDataTable(list);
    }

    /**
     * 导出课程标签列表
     */
    @PreAuthorize("@ss.hasPermi('curriculum:tag:export')")
    @Log(title = "课程标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseTag courseTag)
    {
        List<CourseTag> list = courseTagService.selectCourseTagList(courseTag);
        ExcelUtil<CourseTag> util = new ExcelUtil<CourseTag>(CourseTag.class);
        util.exportExcel(response, list, "课程标签数据");
    }

    /**
     * 获取课程标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('curriculum:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(courseTagService.selectCourseTagById(id));
    }

    /**
     * 新增课程标签
     */
    @PreAuthorize("@ss.hasPermi('curriculum:tag:add')")
    @Log(title = "课程标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseTag courseTag)
    {
        return toAjax(courseTagService.insertCourseTag(courseTag));
    }

    /**
     * 修改课程标签
     */
    @PreAuthorize("@ss.hasPermi('curriculum:tag:edit')")
    @Log(title = "课程标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseTag courseTag)
    {
        return toAjax(courseTagService.updateCourseTag(courseTag));
    }

    /**
     * 删除课程标签
     */
    @PreAuthorize("@ss.hasPermi('curriculum:tag:remove')")
    @Log(title = "课程标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseTagService.deleteCourseTagByIds(ids));
    }

    /**
     * 修改tag状态
     * @param tag
     * @return
     */
    @Log(title = "课程标签",businessType = BusinessType.UPDATE)
    @PostMapping("/changeTagStatus")
    public AjaxResult changeTagStatus(@RequestBody CourseTag tag){
      return toAjax(courseTagService.changeTagStatus(tag));
    }
}
